﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using FlotasDesktop;

namespace GestorDeFlotasDesktop.AbmChofer
{
    public partial class BajaChofer : Form
    {
        int id;
        String conexion;
        public BajaChofer()
        {
            InitializeComponent();
            Utils utils = new Utils();
            conexion = utils.cargarProperties();
            
        }

        internal void mostrateConCampos(String idChofer, String nombre, String apellido, String dni, String telefono, String direccion, String mail, DateTime fechaNacimiento, Boolean habilitiado)
        {

            this.id = Convert.ToInt32(idChofer);
            nombreTextBox.Text = nombre;
            apellidoTextBox.Text = apellido;
            dniTextBox.Text = dni;
            telefonoTextBox.Text = telefono;
            direccionTextBox.Text = direccion;
            mailTextBox.Text = mail;
            fechaNacimientoMonthCalendar.SetDate(fechaNacimiento.Date);
            this.Show();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            using (SqlConnection connection = new SqlConnection(conexion))
            {
                try
                {
                    using (SqlCommand command = new SqlCommand())
                    {

                        connection.Open();
                        command.Connection = connection;
                        command.CommandType = System.Data.CommandType.StoredProcedure;
                        command.CommandText = "TEQUILASO.sp_bajaChofer";
                        command.Parameters.AddWithValue("@Id", this.id);
                        command.ExecuteNonQuery();
                        connection.Close();
                        this.Close();
                        MessageBox.Show("Baja realizada con éxito");

                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }


    }
}